package servlet.initparam;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class GreetingServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//요청파라미터 조회
		
		//1. 요청정보 한글처리
		request.setCharacterEncoding("UTF-8");
		String name = request.getParameter("name");
		
		//2. 초기 파라미터 조회
		ServletConfig conf = getServletConfig();
		String greeting1 = conf.getInitParameter("greeting");
		String greeting2 = getInitParameter("greeting2");
		
		//2-2. Application단위의 초기파라미터 조회
		// ServletContext객체 조회
		ServletContext context = getServletContext();
		String adminEmail = context.getInitParameter("admin email");
		String companyAddress = context.getInitParameter("company address");
		
		//3. 처리 결과 응답
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println("<html><body>");
		//name : 요청파라미터, greeting1/2 : 초기파라미터 
		out.println(name + "님" + greeting1 + greeting2);
		out.println("<hr>관리자 이메일 : " + adminEmail + ", 회사주소 : " + companyAddress);
		out.println("</body></html>");
		
		
	}

}
